package com.service.system.order.impl;

import com.dao.*;
import com.entity.system.*;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.service.system.businessShop.BusinessShopService;
import com.service.system.order.OrderService;
import com.util.*;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.text.ParseException;
import java.util.*;

@Service
public class OrderServiceImpl implements OrderService{

    @Autowired
    OrderMapper orderMapper;

    @Autowired
    UserInfoMapper userInfoMapper;

    @Autowired
    WithdrawalHistoryOrderMapper withdrawalHistoryOrderMapper;

    @Autowired
    SystemGlobalConfigMapper systemGlobalConfigMapper;

    @Autowired
    UserAssetsMapper userAssetsMapper;

    @Autowired
    UserCashFlowMapper userCashFlowMapper;

    @Autowired
    SystemMessageMapper systemMessageMapper;

    @Autowired
    NewsCycleMapper newsCycleMapper;

    @Autowired
    BusinessShopService businessShopService;

    @Autowired
    OrderPayMapper orderPayMapper;

    @Autowired
    HatProvinceMapper hatProvinceMapper;

    @Autowired
    HatCityMapper hatCityMapper;

    @Autowired
    HatAreaMapper hatAreaMapper;

    @Autowired
    UserAuthenticationTempMapper userAuthenticationTempMapper;

    @Autowired
    UserAuthenticationMapper userAuthenticationMapper;

    @Override
    public Map<String, Object> findOrderByUser(Long userId,String pageSize,String pageNum,String startTime,String endTime,String phone,String orderState) {
        Map<String,Object> map = new HashMap<String, Object>();
        if(StringUtils.isEmpty(pageNum)){
            pageNum = "1";
        }
        if(StringUtils.isEmpty(pageSize)){
            pageSize = "10";
        }
        if(StringUtils.isNotEmpty(startTime)){
            map.put("startTime",startTime);
        }
        if(StringUtils.isNotEmpty(endTime)){
            map.put("endTime",endTime);
        }
        if(StringUtils.isNotEmpty(orderState)){
            map.put("orderState",orderState);
        }
        if(StringUtils.isNotEmpty(phone)){
            Map<String,Object> map1 = userInfoMapper.findUserIdByPhone(phone);
            if(map1 != null){
                map.put("userId",map1.get("id"));
            }else {
                map.put("userId","");
            }

        }
        PageHelper.startPage(Integer.parseInt(pageNum),Integer.parseInt(pageSize));
        List<Order> list = orderMapper.findOrderByUser(map);
        PageInfo<Order> pageInfo = new PageInfo<>(list);
        List<Order> orders = pageInfo.getList();
        for(Order order : orders){
            order.setPhone(userInfoMapper.findPhoneByUserId(order.getUserId()));
            map.clear();
            map.put("orderNo",order.getOrderNo());
            OrderPay orderPay = orderPayMapper.findByMap(map);
            if(null != orderPay){
                if(orderPay.getPayChannel() == 1){
                    order.setPayChannel("支付宝");
                }else if(orderPay.getPayChannel() == 2){
                    order.setPayChannel("微信");
                }else if(orderPay.getPayChannel() == 3){
                    order.setPayChannel("零钱");
                }
            }
        }
        map.clear();
        map.put("code", Const.SUCCESS_CODE);
        map.put("message","查询成功");
        map.put("page",pageInfo);
        map.put("orders",orders);
        return map;
    }

    @Override
    public Map<String, Object> fundOrderList(Map<String, String> map) {
        Map<String,Object> map1 = new HashMap<>();
        int pageSize = 10;
        int pageNum = 1;
        if(StringUtils.isNotEmpty(map.get("pageSize"))){
            pageSize = Integer.parseInt(map.get("pageSize"));
        }
        if(StringUtils.isNotEmpty(map.get("pageNum"))){
            pageNum = Integer.parseInt(map.get("pageNum"));
        }
        PageHelper.startPage(pageNum,pageSize);
        List<Order> order = orderMapper.fundOrderList(map);
        PageInfo<Order> pageInfo = new PageInfo<>(order);
        List<Order> list = pageInfo.getList();
        for(Order order1 : list){
            UserInfo userInfo = userInfoMapper.findUserById(order1.getUserId());
            if(null != userInfo){
                order1.setNickName(userInfo.getNickName());
                order1.setPhone(userInfo.getPhone());
                if(userInfo.getSex() == 0){
                    order1.setSex("男");
                }else {
                    order1.setSex("女");
                }
            }
        }
        map1.put("code", Const.SUCCESS_CODE);
        map1.put("message","查询成功");
        map1.put("orderList",list);
        map1.put("page",pageInfo);
        return map1;
    }

    @Override
    public Map<String, Object> findWithdrawalList(Map<String, Object> map,AgentNew agentNew) {
        Map<String,Object> map1 = new HashMap<>();
        int pageSize = 10;
        int pageNum = 1;
        if(StringUtils.isNotEmpty(map.get("pageSize").toString())){
            pageSize = Integer.parseInt(map.get("pageSize").toString());
        }
        if(StringUtils.isNotEmpty(map.get("pageNum").toString())){
            pageNum = Integer.parseInt(map.get("pageNum").toString());
        }
        if(null != map.get("phone")){
            UserInfo userInfo =  userInfoMapper.findUserByPhone(map.get("phone").toString());
            if(null == userInfo){
                map1.put("code",Const.ERROR_CODE);
                map1.put("message","不存在该号码的用户");
                return map1;
            }
            map.put("userId",userInfo.getId()+"");
        }

        if(null != agentNew){
            if(agentNew.getAgentLevel() == 1){
                String area = hatAreaMapper.findByAreaId(agentNew.getCountyCode()).getArea();
                String city = hatCityMapper.findByCityId(agentNew.getCityCode()).getCity();
                String province = hatProvinceMapper.findByProvinceId(agentNew.getProvinceCode()).getProvince();
                map1.put("area",area.substring(0,area.length()-1)+"%");
                map1.put("city",city.substring(0,city.length()-1)+"%");
                map1.put("province",province.substring(0,province.length()-1)+"%");
            }else if(agentNew.getAgentLevel() == 2){
                String city = hatCityMapper.findByCityId(agentNew.getCityCode()).getCity();
                String province = hatProvinceMapper.findByProvinceId(agentNew.getProvinceCode()).getProvince();
                map1.put("city",city.substring(0,city.length()-1)+"%");
                map1.put("province",province.substring(0,province.length()-1)+"%");
            }else if(agentNew.getAgentLevel() == 3){
                String province = hatProvinceMapper.findByProvinceId(agentNew.getProvinceCode()).getProvince();
                map1.put("province",province.substring(0,province.length()-1)+"%");
            }
            map1.put("certificationType",2);
            List<Long> userIds = userAuthenticationMapper.findUserIdByMap(map1);
            if(userIds.size() > 0){
                map.put("userIds",userIds);
            }else {
                map1.put("code",Const.SUCCESS_CODE);
                map1.put("message","暂无数据");
                return map1;
            }

        }

        PageHelper.startPage(pageNum,pageSize);
        List<WithdrawalHistoryOrder> list = withdrawalHistoryOrderMapper.findByMap(map);
        PageInfo<WithdrawalHistoryOrder> pageInfo = new PageInfo<>(list);
        List<WithdrawalHistoryOrder> withdrawalHistoryOrders = pageInfo.getList();
        int inviteAward = 0;
        String key = "";

        for(WithdrawalHistoryOrder who : withdrawalHistoryOrders){
            if(who.getType() != null && who.getType() == 2){
                key = "client.config.inviteAward..withDrawlsFee";//推荐奖励金审核最低提现配置KEY
            }else if(who.getType() != null && who.getType() == 3){
                key = "client.config.studyAward.withDrawlsFee";//学习奖励金审核最低提现配置KEY
            }else if(who.getType() != null && who.getType() == 1){
                key = "client.config.withDrawlsFee";//零钱审核最低提现配置KEY
            }else if(who.getType() != null && who.getType() == 4){
                key = "client.config.withDrawlsFeeByConsumerMoney"; //消费金营业额提现手续费配置
            }
            map1.put("configKey",key);
            map1.put("state", 1);
            map1.put("configGroup", "client");
            SystemGlobalConfig systemGlobalConfig = systemGlobalConfigMapper.findByMap(map1);
            if(null != systemGlobalConfig){
                inviteAward = Integer.parseInt(systemGlobalConfig.getConfigContent());
            }else {
                inviteAward = 0;
            }
            who.setPrice(who.getPrice()/100);
            who.setHandlingCharge((double) inviteAward * who.getPrice()/100);
            if(StringUtils.isEmpty(who.getCurrentApproverName()) && null != who.getAuditUserId()){
                UserInfo userInfo = userInfoMapper.findUserById(who.getAuditUserId());
                if(null != userInfo){
                    who.setCurrentApproverName(userInfo.getNickName());
                }
            }
            UserInfo userInfo = userInfoMapper.findUserById(who.getUserId());
            if(null != userInfo){
                who.setPhone(userInfo.getPhone());
                who.setNickName(userInfo.getNickName());
            }
        }
        map1.clear();
        map1.put("code",Const.SUCCESS_CODE);
        map1.put("message","查询成功");
        map1.put("withdrawalHistoryOrders",withdrawalHistoryOrders);
        map1.put("page",pageInfo);
        return map1;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Map<String, Object> withdrawaAudit(String id, String type, String content) {
        Map<String,Object> map = new HashMap<>();
        int num = 0;
        Subject currentUser = SecurityUtils.getSubject();
        Session session = currentUser.getSession();
        UserInfo userInfo = (UserInfo) session.getAttribute(Const.SESSION_USER);
        //审核通过
        if("1".equals(type)){
            WithdrawalHistoryOrder withdrawalHistoryOrder = withdrawalHistoryOrderMapper.selectByPrimaryKey(Long.parseLong(id));
            if(null == withdrawalHistoryOrder){
                map.put("code",Const.ERROR_CODE);
                map.put("message","提现申请不存在");
                return map;
            }
            if(withdrawalHistoryOrder.getIsAuditPass() == 1){
                map.put("code",Const.ERROR_CODE);
                map.put("message","提现申请已经审核过了");
                return map;
            }
            withdrawalHistoryOrder.setAuditUserId(userInfo.getId());
            withdrawalHistoryOrder.setCurrentApproverName(userInfo.getNickName());
            int woType = Integer.parseInt(withdrawalHistoryOrder.getType().toString());
            Double fee = 0.0;
            String key = "client.config.withDrawlsFee";//手续费全局配置key
            if(woType == 1){
                //零钱手续费率
                key = "client.config.withDrawlsFee";
            }else if(woType == 2){
                //推荐金提现
                key = "client.config.inviteAward..withDrawlsFee";
            }else if(woType == 3){
                //学习金提现
                key = "client.config.studyAward.withDrawlsFee";
            }else if(woType == 4){
                //消费金营业额提现手续费配置
                key = "client.config.withDrawlsFeeByConsumerMoney";
            }
            map.put("configKey",key);
            map.put("state",1);
            SystemGlobalConfig systemGlobalConfig = systemGlobalConfigMapper.findByMap(map);
            map.clear();
            if(null == systemGlobalConfig){

                map.put("code",Const.ERROR_CODE);
                map.put("message","审核失败,手续费配置信息为空");
                return map;
            }
            if(systemGlobalConfig.getConfigMax() >= Integer.valueOf(systemGlobalConfig.getConfigContent()) && Integer.valueOf(systemGlobalConfig.getConfigContent()) >= systemGlobalConfig.getConfigMin()){
                fee = Double.valueOf(systemGlobalConfig.getConfigContent()) / 100; // 本次提现需要扣除的手续费比例
            }else {
                map.put("code",Const.ERROR_CODE);
                map.put("message","审核失败,手续费配置不在最大值和最小值之间");
                return map;
            }
            //微信提现
            Map<String,Object> map1 = weixinwithdrawalRequst(withdrawalHistoryOrder,fee,woType);
            LogUtil.info("**********微信提现 map:"+map1.toString());

            map.put("withdrawalOrderId",withdrawalHistoryOrder.getId());
            List<UserCashFlow> userCashFlows = userCashFlowMapper.findByMap(map);
            if(Integer.parseInt(map1.get("code").toString()) == 2  && !"余额不足".equals(map1.get("message").toString())){
                if(null != userCashFlows && userCashFlows.size() > 0){
                    for(UserCashFlow userCashFlow : userCashFlows){
                        if(userCashFlow.getIsSuccess() == 0){
                            LogUtil.info("提现历史信息ID:"+userCashFlow.getWithdrawalOrderId()+"------删除流水信息ID:"+userCashFlow.getId());
                            userCashFlowMapper.deleteByWoId(userCashFlow.getWithdrawalOrderId());
                        }
                    }
                }
            }else if(Integer.parseInt(map1.get("code").toString()) == 1){
                if(null != userCashFlows && userCashFlows.size() > 0){
                    for(UserCashFlow userCashFlow : userCashFlows){
                        LogUtil.info("提现历史信息ID:"+userCashFlow.getWithdrawalOrderId()+"------修改流水信息ID:"+userCashFlow.getId());
                        userCashFlow.setIsSuccess(1);
                        userCashFlowMapper.updateByPrimaryKeySelective(userCashFlow);
                    }
                }
                //走马灯信息
                UserInfo userInfo1 = userInfoMapper.findUserById(withdrawalHistoryOrder.getUserId());
                NewsCycle newsCycle = new NewsCycle();
                newsCycle.setAdvertName("用户提现");
                newsCycle.setAdvertType(12);// 提现
                newsCycle.setPlanPlayTime(new Date());
                newsCycle.setTopFlag(0);
                newsCycle.setPlayCount(0);
                newsCycle.setSource(0);
                newsCycle.setState(0);
                newsCycle.setAdvertId(withdrawalHistoryOrder.getId());
                if(null != userInfo1){
                    DecimalFormat format = new DecimalFormat("0.00#");
                    double re = withdrawalHistoryOrder.getPrice() / 100;
                    if(StringUtils.isNotEmpty(userInfo1.getPhone())){
                        String phone = userInfo1.getPhone();
                        phone = phone.substring(0, 3) + "****" + phone.substring(7);
                        newsCycle.setPlayContent("\"" + phone + "\"提现了" + (format.format(re)) + "元");
                    }else {
                        String nickName = userInfo1.getNickName();
                        newsCycle.setPlayContent("\"" + nickName + "\"提现了" + (format.format(re)) + "元");
                    }
                }
                newsCycleMapper.insert(newsCycle);
                //添加系统消息
                String auditContent = "亲，恭喜您！您的提现申请已经审核通过。到账"+withdrawalHistoryOrder.getPrice()/100.0+"元，请您尽快查询账户！";
                SystemMessage systemMessage = new SystemMessage();
                systemMessage.setContent(auditContent);
                systemMessage.setCreateTime(new Date());
                systemMessage.setUserId(withdrawalHistoryOrder.getUserId());
                systemMessageMapper.insertSelective(systemMessage);

                try {
                    businessShopService.shareApp(userInfo1.getId(), (long) 7);
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
            map.clear();
            map = map1;

        }else {//审核不通过
            WithdrawalHistoryOrder withdrawalHistoryOrder = withdrawalHistoryOrderMapper.selectByPrimaryKey(Long.parseLong(id));
            if(null == withdrawalHistoryOrder){
                map.put("code",Const.ERROR_CODE);
                map.put("message","审核失败,提现申请不存在");
                return map;
            }
            withdrawalHistoryOrder.setModifyTime(new Date());
            withdrawalHistoryOrder.setIsAuditPass(1);
            withdrawalHistoryOrder.setState((byte)3);
            withdrawalHistoryOrder.setCurrentApproverName(userInfo.getNickName());
            withdrawalHistoryOrder.setAuditUserId(userInfo.getId());
            num = withdrawalHistoryOrderMapper.updateByPrimaryKeySelective(withdrawalHistoryOrder);
            if(num == 1){
                // 把前面扣除用户的钱给用户加上
                UserAssets userAssets = userAssetsMapper.findUserAssetsByUserId(withdrawalHistoryOrder.getUserId());
                if(null == userAssets){
                    map.put("code",Const.ERROR_CODE);
                    map.put("message","审核失败,用户:"+withdrawalHistoryOrder.getUserId()+"账户不存在");
                    return map;
                }
                Integer priceType = new Integer(withdrawalHistoryOrder.getType());
                LogUtil.info("回滚中的priceType : " + priceType + ",先前提现订单的金额 ： " + withdrawalHistoryOrder.getPrice());
                if(priceType != null && priceType == 2){//推荐奖励金
                    userAssets.setAwardCashBalance(userAssets.getAwardCashBalance().add(BigDecimal.valueOf(withdrawalHistoryOrder.getPrice())));
                }else if(priceType != null && priceType == 3){//学习奖励金
                    userAssets.setTaskAwardBalance(userAssets.getTaskAwardBalance() + withdrawalHistoryOrder.getPrice());
                }else if(priceType != null && priceType == 1){ //零钱
                    userAssets.setCashBalance(userAssets.getCashBalance().add(BigDecimal.valueOf(withdrawalHistoryOrder.getPrice())));
                }else if(priceType != null && priceType == 4){ //消费金营业额
                    userAssets.setBusinessConsumerMoneyBalance(userAssets.getBusinessConsumerMoneyBalance().add(BigDecimal.valueOf(withdrawalHistoryOrder.getPrice())));
                }
                userAssets.setModifyTime(new Date());
                num = userAssetsMapper.updateByPrimaryKeySelective(userAssets);
                // 删除流水信息
                map.put("withdrawalOrderId",withdrawalHistoryOrder.getId());
                List<UserCashFlow> userCashFlows = userCashFlowMapper.findByMap(map);
                if(null != userCashFlows && userCashFlows.size() > 0){
                    for(UserCashFlow userCashFlow : userCashFlows){
                        if(userCashFlow.getIsSuccess() == 0){
                            LogUtil.info("提现历史信息ID:"+userCashFlow.getWithdrawalOrderId()+"------删除流水信息ID:"+userCashFlow.getId());
                            userCashFlowMapper.deleteByWoId(userCashFlow.getWithdrawalOrderId());
                        }
                    }
                }
                //添加系统消息
                SystemMessage systemMessage = new SystemMessage();
                systemMessage.setContent("您的提现未通过审核，原因是："+content);
                systemMessage.setCreateTime(new Date());
                systemMessage.setUserId(withdrawalHistoryOrder.getUserId());
                num = systemMessageMapper.insertSelective(systemMessage);
                map.put("code",Const.SUCCESS_CODE);
                map.put("message","审核成功");
            }else {
                map.put("code",Const.ERROR_CODE);
                map.put("message","审核失败");
            }
        }
        return map;
    }

    /**
     * 向微信发起提现请求
     * @param withdrawalHistoryOrder
     * @param fee
     * @param woType
     * @return
     */
    private Map<String,Object> weixinwithdrawalRequst(WithdrawalHistoryOrder withdrawalHistoryOrder,Double fee,int woType){
        Map<String,Object> map = new HashMap<>();
        ResourceBundle rs = ResourceBundle.getBundle("environment");

        String mch_appid = rs.getString("weixin.mch_appid");// "wx11062cf326bb09bb";
        String mchid = rs.getString("weixin.mchid");// "1315715001";
        String nonce_str = new Date().getTime() + "";
        String check_name = rs.getString("weixin.check_name");// "NO_CHECK";
        String desc = "mouchina";
        String spbill_create_ip = rs.getString("weixin.spbill_create_ip");// "117.33.106.44";
        String signkey = rs.getString("weixin.signkey");// "mmc201603201200xKxLx4o8PJ1afCtk9";
        String certPath = rs.getString("weixin.cert_path");//签名文件在服务器放置的路径

        LogUtil.info("传入微信提现接口的钱数 : " +  (withdrawalHistoryOrder.getPrice() * (1 - fee)));

        String stringSign = "amount=" + (int) (withdrawalHistoryOrder.getPrice() * (1 - fee)) + "&check_name="
                + check_name + "&desc=" + desc + "&mch_appid=" + mch_appid + "&mchid=" + mchid + "&nonce_str="
                + nonce_str + "&openid=" + withdrawalHistoryOrder.getAccount() + "&partner_trade_no="
                + withdrawalHistoryOrder.getWithdrawlHistoryOrderNo() + "&spbill_create_ip=" + spbill_create_ip
                + "&key=" + signkey;
        LogUtil.info("签名信息StringSign : " + stringSign);
        String sign = MD5Util.md5Hex(stringSign).toUpperCase();

        Map<String, String> requestMap = new HashMap<>();
        requestMap.put("mch_appid", mch_appid + "");
        requestMap.put("mchid", mchid + "");
        requestMap.put("nonce_str", nonce_str + "");
        requestMap.put("partner_trade_no", withdrawalHistoryOrder.getWithdrawlHistoryOrderNo());
        requestMap.put("openid", withdrawalHistoryOrder.getAccount());

        requestMap.put("amount", (int) (withdrawalHistoryOrder.getPrice() * (1 - fee)) + "");
        requestMap.put("check_name", check_name);
        requestMap.put("desc", desc);
        requestMap.put("spbill_create_ip", spbill_create_ip);
        requestMap.put("sign", sign);

        LogUtil.info("向微信发起请求的参数:"+requestMap.toString());
        String requestXml = XMLBeanUtils.getXmlWeiXinInfo(requestMap);
        LogUtil.info("封装后的XML:"+requestXml);

        String payment_no = "";// 第三方订单号(微信订单号)
        String rep_partner_trade_no = ""; //微信返回商户订单号
        try {
            requestXml = new String(requestXml.getBytes("utf-8"));
            LogUtil.info("*********************调用微信企业支付接口*************************");
            String respon = WeiXinPayUtils.wexinPay(requestXml,certPath,mchid);// 获取微信提现结果响应信息
            LogUtil.info("微信提现返回报文XML:"+respon);
            Map<String,String> map1 = XMLBeanUtils.readStringXmlOut(respon);
            LogUtil.info("微信提现返回报文Map:"+map1);

            if("SUCCESS".equals(map1.get("return_code"))){
                if("SUCCESS".equals(map1.get("result_code"))){
                    payment_no = map1.get("payment_no");
                    rep_partner_trade_no = map1.get("partner_trade_no");

                    withdrawalHistoryOrder.setThirdPartyPayNo(payment_no);
                    withdrawalHistoryOrder.setFinishTime(new Date());
                    withdrawalHistoryOrder.setModifyTime(new Date());
                    withdrawalHistoryOrder.setState((byte) 2);
                    withdrawalHistoryOrder.setIsAuditPass(1);
                    int num = withdrawalHistoryOrderMapper.updateByPrimaryKeySelective(withdrawalHistoryOrder);
                    if(num == 1){
                        map.put("code",Const.SUCCESS_CODE);
                        map.put("message","审核成功");
                    }else {
                        map.put("code",Const.ERROR_CODE);
                        map.put("message","审核失败(微信提现成功,修改提现历史记录失败,请联系管理员)");
                        LogUtil.info("审核失败(微信提现成功,修改提现历史记录失败,请联系管理员)");
                    }
                    LogUtil.info("提现成功----微信订单号:"+payment_no+"-----微信返回商户订单号:"+rep_partner_trade_no);
                }else {
                    LogUtil.info("提现失败----err_code:"+map1.get("err_code")+"------err_code_des:"+map1.get("err_code_des"));
                    //余额不足
                    if("NOTENOUGH".equals(map1.get("err_code"))){
                        withdrawalHistoryOrder.setModifyTime(new Date());
                        withdrawalHistoryOrder.setFinishTime(new Date());
                        withdrawalHistoryOrder.setState((byte) 3); //提现失败
                        withdrawalHistoryOrder.setIsAuditPass(0);
                        map.put("code",Const.ERROR_CODE);
                        map.put("message","余额不足");
                    }else {
                        LogUtil.info("**************提现失败,账户回滚*********************");
                        withdrawalHistoryOrder.setModifyTime(new Date());
                        withdrawalHistoryOrder.setFinishTime(new Date());
                        withdrawalHistoryOrder.setState((byte) 3); //提现失败
                        withdrawalHistoryOrder.setIsAuditPass(1);
                        UserAssets userAssets = userAssetsMapper.findUserAssetsByUserId(withdrawalHistoryOrder.getUserId());
                        if(null == userAssets){
                            map.put("code",Const.ERROR_CODE);
                            map.put("message","审核失败,用户:"+withdrawalHistoryOrder.getUserId()+"账户不存在");
                            return map;
                        }
                        if(woType == 2){ //推荐奖励金
                            userAssets.setAwardCashBalance(userAssets.getAwardCashBalance().add(BigDecimal.valueOf(withdrawalHistoryOrder.getPrice())));
                        }else if(woType == 3){ //学习奖励金
                            userAssets.setTaskAwardBalance(userAssets.getTaskAwardBalance() + withdrawalHistoryOrder.getPrice());
                        }else if(woType == 1){ //零钱
                            userAssets.setCashBalance(userAssets.getCashBalance().add(BigDecimal.valueOf(withdrawalHistoryOrder.getPrice())));
                        }else if(woType == 4){ //消费金营业额
                            userAssets.setBusinessConsumerMoneyBalance(userAssets.getBusinessConsumerMoneyBalance().add(BigDecimal.valueOf(withdrawalHistoryOrder.getPrice())));
                        }
                        userAssets.setModifyTime(new Date());
                        int num = userAssetsMapper.updateByPrimaryKeySelective(userAssets);
                        map.put("code",Const.ERROR_CODE);
                        map.put("message",map1.get("err_code_des"));
                    }
                    int num = withdrawalHistoryOrderMapper.updateByPrimaryKeySelective(withdrawalHistoryOrder);

                }
            }else {
                map.put("code",Const.ERROR_CODE);
                map.put("message",map1.get("return_msg"));
                LogUtil.info("提现失败----return_msg:"+map1.get("return_msg"));
            }

        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return map;
    }
}
